package com.naml.d_outputstream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/22 21:28
 * @desc 演示使用 FileOutputStream 拷贝视频/图片的数据。
 */
@SuppressWarnings("all")
public class FileCopy06 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;
        try {
            String path = "/Users/marin/图片1.png";
            String outPath = "/Users/marin/图片2.png";
            //从磁盘读取数据到程序中
            fileInputStream = new FileInputStream(path);
            fileOutputStream = new FileOutputStream(outPath);
            int length = 0;
            //提高读取效率
            byte[] buffer = new byte[1024];
            while ((length = fileInputStream.read(buffer)) != -1) {
                //读取到部分数据后，写入到文件
                fileOutputStream.write(buffer, 0, length);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOutputStream != null){
                fileOutputStream.close();
            }
            if (fileInputStream != null){
                fileInputStream.close();
            }
        }
    }
}
